package 领扣算法.A简单题.按照频率将数组升序排序;

import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.HashMap;

public class Main {
    
    public int[] frequencySort(int[] nums) {
        HashMap<Integer,Integer> data=new HashMap<>();
        for (int i : nums) {
            data.put(i, data.getOrDefault(i,0)+1);
        }
        int res[][] =new int[data.size()][2];
        int i=0;
        for (int key : data.keySet()) {
            res[i++]=new int[]{key,data.get(key)};

        }
        Arrays.sort(res,(a,b)->(b[0]-a[0]));
        Arrays.sort(res,(a,b)->(a[1]-b[1]));
        
        i=0;
        for (int j = 0; j < res.length; j++) {
            for(int k=0;k<res[j][1];k++)
                nums[i++]=res[j][0];
        }
        return nums;
    }
}
